package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.vo.ActivityListVO;
import cn.scxy.bookcity.pojo.vo.HotSearchListVO;
import cn.scxy.bookcity.pojo.vo.PackListVO;
import cn.scxy.bookcity.service.IAdminCilentService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 张正荣
 */
@RestController
@RequestMapping("/adminCilent")
@Api(tags = "管理员前台（热搜/活动）管理")
@Slf4j
public class AdminCilentController {
    @Autowired
    IAdminCilentService service;
    @ApiOperation("查询热搜列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/hotlist")
    public JsonResult< List<HotSearchListVO>> selectHotList(){
       List<HotSearchListVO> list= service.selectHotList();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询热搜列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/activitylist")
    public JsonResult< List<ActivityListVO>> selectActivitylist(){
       List<ActivityListVO> list= service.selectActivitylist();
        return JsonResult.ok(list);
    }
    @ApiOperation("显示热搜")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("开始处理【启用类别】的请求，参数：{}", id);
        service.setEnable(id);
        return JsonResult.ok();
    }

    // http://localhost:8080//9527/disable
    @ApiOperation("关闭热搜")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("开始处理【禁用类别】的请求，参数：{}", id);
        service.setDisable(id);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除热搜信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/{id:[0-9]+}/deleteHot")
    public JsonResult<Void> deleteHot(@PathVariable Long id) {
        log.debug("根据id删除热搜信息{}", id);
        service.deleteHot(id);
        return JsonResult.ok();
    }
    @ApiOperation("添加热搜信息")
    @ApiOperationSupport(order = 311)
    @PostMapping("/insetHot")
    public JsonResult<Void> insetHot(HotSearchListVO packListVO) {
        log.debug("修改出版社信息{}",packListVO);
        service.insetHot(packListVO);
        return JsonResult.ok();
    }
    @ApiOperation("显示热搜")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/enable1")
    public JsonResult<Void> setEnable1(@PathVariable Long id) {
        log.debug("开始处理【启用类别】的请求，参数：{}", id);
        service.setEnable1(id);
        return JsonResult.ok();
    }

    // http://localhost:8080//9527/disable
    @ApiOperation("关闭热搜")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/disable1")
    public JsonResult<Void> setDisable1(@PathVariable Long id) {
        log.debug("开始处理【禁用类别】的请求，参数：{}", id);
        service.setDisable1(id);
        return JsonResult.ok();
    }
    @ApiOperation("查询升热搜列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/aschotlist")
    public JsonResult< List<ActivityListVO>> aschotlist(){
        List<ActivityListVO> list= service.aschotlist();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询降序热搜列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/deshotlist")
    public JsonResult< List<ActivityListVO>> deshotlist(){
        List<ActivityListVO> list= service.deshotlist();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询单个热搜列表")
    @ApiOperationSupport(order = 301)
    @PostMapping("/selectLikehot")
    public JsonResult<List<ActivityListVO>> selectLikehot(ActivityListVO activityListVO){
        String name = activityListVO.getName();
        List<ActivityListVO> a  = service.selectLikehot(name);
        return JsonResult.ok(a);
    }

}
